using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Pavilion;

namespace Pavilion.GameTools
{
    public class HealthTool : GameToolBase
    {
        private float amount, total;
        private Layout layout;
        private Rectangle bounds, range;
        private DrawItem drawItem;

        public HealthTool(GameItem parentGameItem) : base(parentGameItem)
        {
            amount = 100;
            layout = Layout.None;
        }

        public override void Load(XElement xmlProperties)
        {
            amount = int.Parse(xmlProperties.Attribute("Amount").Value);
            LayoutDisplay = (Layout)Enum.Parse(typeof(Layout), xmlProperties.Attribute("Layout").Value);
   
            drawItem = new DrawItem(0, () =>
            {
                DrawManager.Instance.FillRectangleOnScreen(range, Color.DarkKhaki);
                DrawManager.Instance.DrawRectangleOnScreen(bounds, Color.Black);
            });

            drawItem.DrawOrder = double.Parse(xmlProperties.Attribute("DrawOrder").Value);

            DrawManager.Instance.Add(drawItem);
            ParentGameItem.DrawVisibilityGroup.Add(drawItem);
        }

        public Layout LayoutDisplay
        {
            get { return layout; }
            set
            {
                this.layout = value;

                if (Layout.Boss == layout)
                    bounds = new Rectangle(GameEngine.WindowWidth / 2 - 400, 15, 800, 10);
                if (Layout.BottomLeft == layout)
                    bounds = new Rectangle(60, GameEngine.WindowHeight - 30, 550, 10);
                if (Layout.BottomRight == layout)
                    bounds = new Rectangle(670, GameEngine.WindowHeight - 30, 550, 10);
                if (Layout.None == layout)
                    bounds = new Rectangle();
                if (Layout.TopLeft == layout)
                    bounds = new Rectangle(60, 15, 550, 10);
                if (Layout.TopRight == layout)
                    bounds = new Rectangle(670, 15, 550, 10);

                range = bounds;
                total = bounds.Width;
            }
        }

        public void setHealth(int percent)
        {
            range.Width = bounds.Width * percent / 100;
        }

        public enum Layout
        {
            Boss,
            BottomLeft,
            BottomRight,
            None,
            TopLeft,
            TopRight
        }
    }
}
